package com.lei.baselibrary.base.utils

import android.content.Context
import android.net.ConnectivityManager

/**
 * @ProjectName : MyMall
 * @Author : 雷金泷
 * @Time : 2021/2/25 9:00
 * @Description : 文件描述
 */
object NewWorkUtils {
    //判断网络是否可用
    fun isNetWorkAvailable(context:Context):Boolean{
        val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val networkInfo = cm.activeNetworkInfo
        return networkInfo!=null&&networkInfo.isConnected
    }
    //检测wifi是否连接
    fun isWifiConnected(context: Context):Boolean{
        val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val netWorkInfo = cm.activeNetworkInfo
        return netWorkInfo!=null&&netWorkInfo.type == ConnectivityManager.TYPE_WIFI
    }
    //检测是否有3g连接
    fun is3gConnected(context: Context):Boolean{
        val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val netWorkInfo = cm.activeNetworkInfo
        return netWorkInfo!=null&&netWorkInfo.type == ConnectivityManager.TYPE_MOBILE
    }
}